package com.ruike.alisurface.ui.call;

import com.google.gson.Gson;
import com.ruike.alisurface.base.BaseAty;
import com.ruike.alisurface.bean.IdcardBean;
import com.ruike.alisurface.https.ShopApiHttp;
import com.ruike.alisurface.utils.DateUtil;
import com.voodoo.lib_http.ApiListener;
import com.voodoo.lib_logcat.L;

import org.json.JSONObject;

import java.util.Date;

/**
 * 问诊页基类
 */
public abstract class BaseCallActivity extends BaseAty {
    private static final int MIN_DURATION_SHOW_LOW_QUALITY = 5000; //显示网络不佳最小间隔时间

    private long mSelfLowQualityTime;
    private long mOtherPartyLowQualityTime;


    @Override
    protected int getLayoutResId() {
        return 0;
    }

    @Override
    protected void initViews() {

    }

    @Override
    protected void initData() {

    }

    public IdcardBean setIdCardData(String json, String order_id, ApiListener apiListener) {
//        String idcard = "{\"address\":\"浙江省永嘉县碧莲镇澄田村澄川中路53号\",\"angle\":0,\"birth\":\"19891130\",\"card_region\":[{\"x\":80,\"y\":158},{\"x\":1517,\"y\":174},{\"x\":1542,\"y\":1118},{\"x\":44,\"y\":1101}],\"config_str\":\"{\\\"side\\\":\\\"face\\\"}\",\"face_rect\":{\"angle\":0,\"center\":{\"x\":1212,\"y\":589},\"size\":{\"height\":464,\"width\":542}},\"face_rect_vertices\":[{\"x\":981,\"y\":317},{\"x\":1446,\"y\":319},{\"x\":1444,\"y\":861},{\"x\":979,\"y\":860}],\"is_fake\":false,\"name\":\"陈建领\",\"nationality\":\"汉\",\"num\":\"330324198911306650\",\"request_id\":\"5484105A-56D2-4C02-8BB2-7271BDD0FF3A\",\"sex\":\"男\",\"success\":true}";
        IdcardBean idcardBean = new Gson().fromJson(json, IdcardBean.class);
        try {
            JSONObject orderObject = new JSONObject();
            orderObject.put("order_id", order_id);
            orderObject.put("name", idcardBean.getName());
            orderObject.put("nationality", idcardBean.getNationality());
            orderObject.put("num", idcardBean.getNum());
            orderObject.put("sex", idcardBean.getSex());
            orderObject.put("address", idcardBean.getAddress());
            int age = 0;
            if (idcardBean.getNum().length() >= 18) {
                int oldyear = Integer.parseInt(idcardBean.getNum().substring(6, 10));
                int currentyear = DateUtil.getYearDate(new Date(System.currentTimeMillis()));
                age = currentyear - oldyear;
                idcardBean.setAge(age + "");
            }
            orderObject.put("age", age);
            L.i("Idcard 信息=", orderObject.toString());
            ShopApiHttp.remote_update_card_info(orderObject.toString(), apiListener);
        } catch (Exception e) {
            L.i("Idcard Exception  信息=", e.toString());
        }

        return idcardBean;
    }
}
